<?
/**
 * @author Wouter Miltenburg
 * @version 1.0
  */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><?php include 'include/title.php'; ?></title>
        <link rel="stylesheet" href="./css/plaintech.css" type="text/css" />
    </head>
    <body>

<?php
    include 'include/header.php';
?>
    	<div id="body">
<?php
    // Including the database class
    require_once('include/classes/database.class.php');

    // Creating database instance
    $database = new Database();
    $database->openConnection();

    //Kijken of $username en $session wel bestaan
   if(isset($_GET['username']) && isset($_GET['session']) && isset($_POST['name']) && isset($_POST['ram']) && isset($_POST['cpu']) && isset($_POST['hdd']) && isset($_POST['sla'])){

        $username = $_GET['username'];
        $session = $_GET['session'];
        $name = $_POST['name'];
        $ram = $_POST['ram'];
		$cpu = $_POST['cpu'];
        $hdd = $_POST['hdd'];
        $sla = $_POST['sla'];




//Kijken of de session overeenkomt met de username
        $query = "SELECT username, session FROM admin WHERE username = '$username' AND session = '$session'";
        $database->getQuery($query);
        if($database->affectedRows() == 1) {

            echo "<br/>Logged in as: $username <br/><br/>";
            $query = "SELECT name FROM vm_package WHERE name = '$name'";
            $database->getQuery($query);
            if($database->affectedRows() != 1){


                //Create a user in table admin
                 $query = sprintf("INSERT INTO vm_package (name, hdd, ram, cpu, sla) VALUES ('$name', '$hdd', '$ram', '$cpu', '$sla')");
                $affectedRows = $database->doQuery($query);

                echo "Package: $name is added with hdd $hdd, ram $ram and SLA $sla<br /><br/>";

           	            echo "<div id=\"dashboard\">
                        <a href=\"./poptions.php?username=$username&session=$session\">
                            <INPUT TYPE=\"button\" VALUE=\"Dashboard\" Class=\"knop\">
                        </a>
                      </div>
                <br/>";

				echo "<div id=\"logout\">
                        <a href=\"./logout.php?username=$username&session=$session\">
                            <INPUT TYPE=\"button\" VALUE=\"Logout\" Class=\"knop\">
                        </a>
                      </div>
                <br/>";



            } else{
                echo "Package $name already exists.";
            }

        } else{
        echo "Username or password is incorrect. Or the session has expired.";
        }

    }else{
        echo "You didn't fill in the form.";
    }
    $database->closeConnection();
?>

       		</div>
    </body>
</html>